﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using XiaoYuStock.Model;
using XiaoYuStock.Model.Models;
using XiaoYuStock.Model.Request;
using XiaoYuStockAnalysis.BusinessLogic.Business;
using XiaoYuStock.Core;
using System.Threading.Tasks;
using XiaoYuStock.Core.Entities;
namespace XiaoYuStock.WebApp.Controllers
{
    public class DayDataController : BaseController
    {
        private DayDataBusiness currentBus = new DayDataBusiness();
        //
        // GET: /Book/

        public ActionResult Index(DayDataRequest request)
        {
            request.PageSize = 50;
            var result = currentBus.GetList(request);
            ViewBag.IsBuy = request.IsBuy;
            return View(result);
        }
       
        [HttpPost]
        public ActionResult GetDayUpdate(string sharesCodes,string date)
        {
            if (!string.IsNullOrWhiteSpace(sharesCodes))
            {
                DateTime currentDate = DateTime.Now;
                DateTime.TryParse(date, out currentDate);
              //  var sharesModel = new ShareTargetBusiness().Get(sharesCodes);
                //if (sharesModel != null)
                //{
                //    string sourceCode = sharesModel.ShareCode;
                //    sourceCode = Enum.GetName(typeof(SharesType), sharesModel.ShareType).ToLower() + sourceCode;
                   

                //    DayDataFile dataHelper = new DayDataFile();
                //    dataHelper.SharesCode = sourceCode;
                //    dataHelper.Date = currentDate.ToString("yyyy-MM-dd");
                //    var data = dataHelper.GetData();
                //    if (data != null)
                //    {
                //        foreach (var item in data)
                //        {
                //            var m = new DayData();
                //            m.CurrentDate = Convert.ToDateTime(dataHelper.Date + " " + item.Time);
                //            m.CurrentPrice = item.TradePrice;
                //            m.CurrentTime = item.Time;
                //            m.FloatPrice = item.FloatAmount;
                //            m.IsBuy = item.IsBuy;
                //            m.ShareCode = sharesCodes;
                //            m.TradeAmount = item.TradeAmount;
                //            m.TradeCount = item.TradeCount;
                //            currentBus.SynData(m);
                //        }
                //    }
                //}
               
               
                
            }
            else
                return Json(new { status = false });
            return Json(new { status = true });
        }

    }
}
